library(tidyverse)
library(tigris)
library(censusapi)
library(sf)
library(mapview)
library(plotly)
options(
tigris_class = "sf",
tigris_use_cache = T # This stores tigris loads somewhere on your machine for much faster personal loading.
)
This script uses an output from load_safegraph.Rmd which processes down the daily social distancing dataset from Safegraph to just block groups in the Bay Area.
These were the high-level lists of Bay county names, county shapes, and block group IDs from the other script, in case they become useful again.
bay_county_names <-
c(
"Alameda",
"Contra Costa",
"Marin",
"Napa",
"San Francisco",
"San Mateo",
"Santa Clara",
"Solano",
"Sonoma"
)
bay_blockgroups <-
bay_county_names %>%
map(function(x){
block_groups("CA",x,progress_bar=F) %>%
pull(GEOID)
}) %>% unlist()
bay_counties <-
counties("CA", cb = F, progress_bar=F) %>%
filter(NAME %in% bay_county_names)
Also, as part of starting to focus on one of our partners, SJ, here’s a quick way to get all the block groups in SJ. If you want to practice this analysis with another location, or see a specific opportunity to support another partner, then this is where you’d start modifications.
scc_blockgroups <-
block_groups("CA","Santa Clara", cb=F, progress_bar=F)
# Below uses tracts sent to us by San Jose
sj_tracts <- st_read("/Users/juliawagenfehr/pCloud Drive/SFBI/Data Library/San_Jose/CSJ_Census_Tracts/CSJ_Census_Tracts.shp") %>%
st_as_sf() %>%
st_transform(4269)
## Reading layer `CSJ_Census_Tracts' from data source `/Users/juliawagenfehr/pCloud Drive/SFBI/Data Library/San_Jose/CSJ_Census_Tracts/CSJ_Census_Tracts.shp' using driver `ESRI Shapefile'
## Simple feature collection with 219 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 6112856 ymin: 1869687 xmax: 6255982 ymax: 1996555
## epsg (SRID): 2227
## proj4string: +proj=lcc +lat_1=38.43333333333333 +lat_2=37.06666666666667 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000.0001016 +y_0=500000.0001016001 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs
sj_blockgroups <-
scc_blockgroups %>%
st_centroid() %>%
st_join(sj_tracts %>% dplyr::select(geometry), left = F) %>%
st_set_geometry(NULL) %>%
left_join(scc_blockgroups%>% dplyr::select(GEOID), by = "GEOID") %>%
st_as_sf() %>%
dplyr::select(GEOID)
sj_boundary <-
places("CA", cb=F, progress_bar=F) %>%
filter(NAME == "San Jose")
#sj_blockgroups <-
# scc_blockgroups %>%
# dplyr::select(GEOID) %>%
# st_join(sj_boundary %>% dplyr::select(geometry), left = F) #%>%
# st_set_geometry(NULL) %>%
# left_join(scc_blockgroups %>% dplyr::select(GEOID)) %>%
# st_as_sf() # last lines here not necessary because we didn't convert to centroid. thanks for the catch, cameron!
mapview(sj_blockgroups)+mapview(sj_boundary,alpha.region= 0, color = "red", lwd = 4)
Note that in this case, unlike the R Basics example, I don’t convert to centroid before the st_join(), because there are random holes within SJ official geopolitical boundaries (whole different story) that certainly shouldn’t be removed from our analysis. So the st_join() holds onto anything that even touches the SJ boundary. But note there’s a huge rural block group to the east of SJ that comes along for the ride that’s practically the size of SJ, which you may decide to manually remove for the sake of better visualiation for now.
sj_blockgroups <-
sj_blockgroups %>%
filter(!GEOID %in% c("060855135001"))
mapview(sj_blockgroups)
Susan Athey from the GSB has been working on a database of non-pharmaceutical interventions, and it looks robust for the Bay Area. See this main page and the Github repo. The following code loads the Santa Clara County data (you’ll need to clone their repo).
#opts_knit$set(root.dir = "~/GitHub/covid19-intervention-data")
npis <- read_csv("/Users/juliawagenfehr/Documents/GitHub/covid19-intervention-data/npis_raw_03-24-2020.csv")
npis_scc <-
npis %>%
filter(locality == "santa_clara_county") %>%
mutate(
date = data_start %>% as.Date("%m/%d/%Y")
) %>%
dplyr::select(date,type_of_intervention,further_notes_comments) %>%
arrange(date)
kable(
npis_scc,
caption = 'Santa Clara County Non-Pharmaceutical Interventions'
)
| date | type_of_intervention | further_notes_comments |
|---|---|---|
| 2020-01-26 | HE | Virus prevention education published in response to early cases in CA |
| 2020-01-28 | CI | Adult male who had traveled to Wuhan, China and had been self-isolating at home |
| 2020-02-03 | TR_China | Nation-wide restriction of foreigners who have traveled to China in the past 14 days |
| 2020-03-01 | HE | County issues health recommendations for prevention |
| 2020-03-02 | SOE | CA Governor requests money from the Disaster Response Emergency Operations Account to fight COVID-19 |
| 2020-03-04 | SOE | CA Governor declares state of emergency |
| 2020-03-04 | PL | Paid leave policies put in place |
| 2020-03-05 | SDO | Recommendation that persons at higher risk of severe illness should stay home and away from crowded social gatherings |
| 2020-03-09 | SDO | Social distancing for vulnerable/at-risk populations |
| 2020-03-11 | SOE | NA |
| 2020-03-11 | GS_1000 | NA |
| 2020-03-13 | GS_250 | Applies to gambling venues, theme parks, theaters |
| 2020-03-13 | PC | Guidelines for physical closures of schools |
| 2020-03-14 | GS_100 | NA |
| 2020-03-16 | PC | NA |
| 2020-03-16 | CPV | Restrict dine-in options for restaurants/bars |
| 2020-03-17 | NESC | NA |
| 2020-03-17 | SD | NA |
| 2020-03-19 | SD | State-wide issue of “stay at home” order |
| 2020-03-19 | NESC | Non-essential services closed |
| 2020-03-20 | CPV | All city playgrounds closed |
Some type_of_intervention codes are defined on the Github, but some aren’t (I’ve reached out to them to ask).
The NPIs defined are:
You can see the 3/17 shelter in place order coded as SD. I’m sharing this as resource for you to consider how to use. In theory each of these can be added to the social distancing time series as a vertical line. Comparisons could be made between the social distancing metrics of different counties based on the different times they implemented various NPIs, and could be useful to communicate to SJ as well as other partners.